﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ESRI.ArcGIS.Carto;

/// <summary>
/// Summary description for DataConnectDAL
/// </summary>
/// 
namespace BTGISWASECO.DataLayer
{
    public class DataConnectDAL
    {
        ESRI.ArcGIS.Carto.IMap aoMap;
        public DataConnectDAL()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public ESRI.ArcGIS.Carto.IMap ServerDatabaseSDE()
        {
            ESRI.ArcGIS.Server.IServerContext serverContext = null;
            ESRI.ArcGIS.esriSystem.UID pUID = new ESRI.ArcGIS.esriSystem.UIDClass();
            string serverType = "MapServer";
            string serviceName = "BTGISWASECO";
            try
            {
                ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity("Administrator", "123", "localhost");
                ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsServerConnection;
                agsServerConnection =
                new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection("localhost", identity);
                agsServerConnection.Connect();
                ESRI.ArcGIS.Server.IServerObjectManager serverObjectManager = agsServerConnection.ServerObjectManager;
                serverContext = serverObjectManager.CreateServerContext(serviceName, serverType);

                ESRI.ArcGIS.esriSystem.IPropertySet propertySet_Connection = (ESRI.ArcGIS.esriSystem.IPropertySet)serverContext.CreateObject("esriSystem.PropertySet");//tham khảo một ví dụ SDE, thay đổi các giá trị này
                propertySet_Connection.SetProperty("server", "localhost");
                propertySet_Connection.SetProperty("instance", "5151");
                propertySet_Connection.SetProperty("database", "BTGISWASECO");
                propertySet_Connection.SetProperty("user", "sde");
                propertySet_Connection.SetProperty("password", "123");
                propertySet_Connection.SetProperty("version", "sde.DEFAULT");
                ESRI.ArcGIS.Carto.IMapServer mapServer = serverContext.ServerObject as ESRI.ArcGIS.Carto.IMapServer;
                ESRI.ArcGIS.Carto.IMapServerObjects mapServerObjects = mapServer as ESRI.ArcGIS.Carto.IMapServerObjects;
                aoMap = mapServerObjects.get_Map(mapServer.DefaultMapName);
            }
            catch
            {
            }
            return aoMap;
        }
    }
}